package com.youi.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.youi.common.Common;
import com.youi.common.DelStatus;
import com.youi.dao.LeaderstoreDao;
import com.youi.entity.Groupleader;
import com.youi.entity.Groupleaderbank;
import com.youi.entity.Leaderstore;
import com.youi.entity.Userwechat;
import com.youi.service.GroupleaderService;
import com.youi.service.GroupleaderbankService;
import com.youi.service.LeaderstoreService;

@Service
public class LeaderstoreServiceImpl extends BaseServiceImpl<Leaderstore> implements LeaderstoreService{
		
		private LeaderstoreDao leaderstoreDao;
		@Autowired
		private GroupleaderService groupleaderService;
		@Autowired
		private GroupleaderbankService groupleaderbankService;
		@Autowired 
		public void setfaultRecordDao(LeaderstoreDao leaderstoreDao){
			this.leaderstoreDao=leaderstoreDao;
			super.setBaseDAO(leaderstoreDao);
		}

		@Override
		public void getLeaderstoreMsg(List<Leaderstore> leaderstoreList) {
			// TODO Auto-generated method stub
			if (leaderstoreList!=null&&leaderstoreList.size()>0) {
				for (Leaderstore leaderstore : leaderstoreList) {
					Groupleader groupleader=groupleaderService.get(leaderstore.getLeaderId());
					if (groupleader!=null) {
						leaderstore.setName(groupleader.getName());
					}
					
				}
			}
		}

		@Override
		public void getLeaderstoreMsg(Leaderstore leaderstore) {
			// TODO Auto-generated method stub
			if (leaderstore!=null) {
				Groupleader groupleader=groupleaderService.get(leaderstore.getLeaderId());
				if (groupleader!=null) {
					leaderstore.setName(groupleader.getName());
				}
				
			}
		}

		@Override
		public List<Long> getLeaderIdsByName(String name) {
			// TODO Auto-generated method stub
			List<Long> leaderIdList=null;
			Map<String, Object> prams=new HashMap<String, Object>();
			prams.put(Common.DELSTATUS, DelStatus.NODEL);
			Map<String, Object> seachParams=new HashMap<String, Object>();
			seachParams.put("name", name);
			List<Groupleader> groupleaderList=groupleaderService.getByParams(prams, seachParams, null);
			if (groupleaderList!=null&&groupleaderList.size()>0) {
				leaderIdList=new ArrayList<Long>();
				for (Groupleader groupleader : groupleaderList) {
					leaderIdList.add(groupleader.getId());
				}
				return leaderIdList;
			}
			return null;
		}
}